
#include "ProxySetting.h"

CProxySetting::CProxySetting()
{
    m_nPort     = 0;
    m_nVersion  = PROXY_SOCKVER5;
    m_bIsUse    = false;
}

CProxySetting::~CProxySetting()
{

}

bool CProxySetting::Load(CBaseIni * pIni)
{
    if (!pIni)
        return false;

    pIni->ReadStr(SECTION_PROXY, KEY_SERVER, "", m_strServer);
    pIni->ReadStr(SECTION_PROXY, KEY_DOMAIN, "", m_strDomain);
    pIni->ReadStr(SECTION_PROXY, KEY_USERNAME, "", m_strUserName);
    pIni->ReadStr(SECTION_PROXY, KEY_PASSWORD, "", m_strPassword);
    m_nPort    = pIni->ReadInt(SECTION_PROXY, KEY_PORT, 0);
    m_nVersion = pIni->ReadInt(SECTION_PROXY, KEY_VERSION, 0);
    m_bIsUse   = pIni->ReadInt(SECTION_PROXY, KEY_USE, 0);

    if (m_strServer.empty() && !m_strDomain.empty())
    {
        m_strServer = Domain2Ip(m_strDomain.c_str());
    }

    return true;
}

bool CProxySetting::Save(CBaseIni * pIni)
{
    if (!pIni)
        return false;

    pIni->WriteStr(SECTION_PROXY, KEY_SERVER, m_strServer.c_str());
    pIni->WriteStr(SECTION_PROXY, KEY_DOMAIN, m_strDomain.c_str());
    pIni->WriteStr(SECTION_PROXY, KEY_USERNAME, m_strUserName.c_str());
    pIni->WriteStr(SECTION_PROXY, KEY_PASSWORD, m_strPassword.c_str());
    pIni->WriteInt(SECTION_PROXY, KEY_PORT, m_nPort);
    pIni->WriteInt(SECTION_PROXY, KEY_VERSION, m_nVersion);
    pIni->WriteInt(SECTION_PROXY, KEY_USE, m_bIsUse);
    return true;
}
